//
//  HXStyleSwitChingViewController.m
//  HongxuanBluetooth
//
//  Created by 广州弘轩科技发展有限公司 on 2023/8/25.
//

#import "HXStyleSwitChingViewController.h"

@interface HXStyleSwitChingViewController ()
@property (nonatomic,strong)UIImageView *topicdefaultview;//默认主题
@property (nonatomic,strong)UIImageView *subjectselection;//第一个主题选中
@property (nonatomic,strong)UIImageView *subjectselectionone;//第二个主题选中
@property (nonatomic,strong)UIImageView *mainscreen;
@property (nonatomic,strong)UIImageView *statebj;
@end

@implementation HXStyleSwitChingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    self.fd_prefersNavigationBarHidden = YES;
    [self BottomFunction];
}
-(void)BottomFunction{
    
    UIImageView *tabr = [[UIImageView alloc] initWithFrame:CGRectMake(0, kNavHeight-44, winWidth, 44)];
    [self.view addSubview:tabr];
    UIImageView *mainscreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, winWidth, 44)];
    if ([themeColors isEqualToString:@"default"]) {
        mainscreen.image = [UIImage imageNamed:@"styleswitchingmian"];//detailmid
    }else{
        mainscreen.image = [UIImage imageNamed:@"styleswitchingmid"];//detailmid
    }
    
    self.mainscreen = mainscreen;
    [tabr addSubview:mainscreen];
    
    UIImageView *statebj = [[UIImageView alloc] init];
    if([themeColors isEqualToString:@"default"]){
        statebj.backgroundColor = [UIColor blackColor];
    }else{
        statebj.backgroundColor = midnightRGB;
    }
    self.statebj= statebj;
    [self.view addSubview:statebj];
    [statebj mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-34);
        make.height.mas_equalTo(50);
    }];
    
#pragma mark 返回入口
    UIImageView *backview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back"]];
    backview.userInteractionEnabled = YES;
    [self.view addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-37);
        make.width.mas_equalTo(33);
        make.height.mas_equalTo(36);
        make.left.mas_equalTo(26);
    }];
    
    UIButton *backbt = [UIButton buttonWithType:UIButtonTypeCustom];
    [backbt addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [backview addSubview:backbt];
    [backbt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(backview);
    }];
    
    UIImageView *bluetherview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluether"]];
    bluetherview.userInteractionEnabled = YES;
    [self.view addSubview:bluetherview];
    [bluetherview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-52);
        make.height.mas_equalTo(13);
    }];
    
    
//    topicdescription
    UIImageView *topicdescriptionview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"topicdescription"]];
    topicdescriptionview.userInteractionEnabled = YES;
    [self.view addSubview:topicdescriptionview];
    [topicdescriptionview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(bluetherview.mas_top).offset(-19);
        make.height.mas_equalTo(36.67);
        make.width.mas_equalTo(144);
    }];
    
//    主题：theme topicdefault 默认配色
    UIImageView *topicdefaultview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"topicdefault"]];
    topicdefaultview.userInteractionEnabled = YES;
    self.topicdefaultview = topicdefaultview;
    [self.view addSubview:topicdefaultview];
    [topicdefaultview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(tabr.mas_bottom).offset(22);
        make.height.mas_equalTo(117.33);
        make.width.mas_equalTo(314.67);
    }];
//    subjectselection 主题选中显示
    UIImageView *subjectselection = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"subjectselection"]];
    [topicdefaultview addSubview: subjectselection];
    self.subjectselection = subjectselection;
    [subjectselection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(14);
        make.width.height.mas_equalTo(20.33);
    }];
//    simplicity 主题名称
    UIImageView *simplicityname = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"simplicity"]];
    [topicdefaultview addSubview: simplicityname];
    [simplicityname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(subjectselection.mas_right).offset(11.33);
        make.top.mas_equalTo(15);
        make.width.mas_equalTo(126);
        make.height.mas_equalTo(21.33);
    }];
    
    //    simplicity 主题说明
    UIImageView *explainone = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"explainone"]];
    [topicdefaultview addSubview: explainone];
    [explainone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(subjectselection.mas_right).offset(11.33);
        make.top.mas_equalTo(simplicityname.mas_bottom).offset(13.67);
        make.width.mas_equalTo(167.33);
        make.height.mas_equalTo(16.67);
    }];
    
    UIButton *simplicitybt = [UIButton buttonWithType:UIButtonTypeCustom];
    simplicitybt.tag = 1;
    [topicdefaultview addSubview:simplicitybt];
    [simplicitybt addTarget:self action:@selector(subjectsChoice:) forControlEvents:UIControlEventTouchUpInside];
    [simplicitybt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(topicdefaultview);
    }];
    
    [self midnightTheme];
    
}
//midnight 主题
-(void)midnightTheme{
    
    //    主题：theme midnightbj
    UIImageView *topicdefaultview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"midnightbj"]];
    topicdefaultview.userInteractionEnabled = YES;
    [self.view addSubview:topicdefaultview];
    [topicdefaultview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.topicdefaultview.mas_bottom).offset(12.67);
        make.height.mas_equalTo(117.33);
        make.width.mas_equalTo(314.67);
    }];
    //    subjectselection 主题选中显示
    UIImageView *subjectselectionone = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"subjectselection"]];
    [topicdefaultview addSubview: subjectselectionone];
    self.subjectselectionone = subjectselectionone;
    subjectselectionone.hidden = YES;
    [subjectselectionone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(14);
        make.width.height.mas_equalTo(20.33);
    }];
    //    simplicity 主题名称
    UIImageView *simplicityname = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"midnight"]];
    [topicdefaultview addSubview: simplicityname];
    [simplicityname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(subjectselectionone.mas_right).offset(11.33);
        make.top.mas_equalTo(15);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(21);
    }];
        
    //    simplicity 主题说明
    UIImageView *explainone = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"midnightexplain"]];
    [topicdefaultview addSubview: explainone];
    [explainone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(subjectselectionone.mas_right).offset(11.33);
        make.top.mas_equalTo(simplicityname.mas_bottom).offset(13.67);
        make.width.mas_equalTo(167.33);
        make.height.mas_equalTo(16.67);
    }];
        
    UIButton *simplicitybt = [UIButton buttonWithType:UIButtonTypeCustom];
    simplicitybt.tag = 2;
    [topicdefaultview addSubview:simplicitybt];
    [simplicitybt addTarget:self action:@selector(subjectsChoice:) forControlEvents:UIControlEventTouchUpInside];
    [simplicitybt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(topicdefaultview);
    }];
    
    
    if ([themeColors isEqualToString:@"default"]) {
        self.subjectselection.hidden = NO;
        self.subjectselectionone.hidden = YES;
    }else{
        self.subjectselection.hidden = YES;
        self.subjectselectionone.hidden = NO;
    }
}

-(void)back{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    if(self.returnValueBlock){
        self.returnValueBlock();
        [self.navigationController popViewControllerAnimated:YES];
    }
//    [self.navigationController popViewControllerAnimated:YES];
}
-(void)subjectsChoice:(UIButton *)button{
    
    GCDSinglePerson *gcdPerson = [GCDSinglePerson sharedPerson];
    NSLog(@"选中了那个主题");
    if(button.tag == 1){
        self.subjectselection.hidden = NO;
        self.subjectselectionone.hidden = YES;
        
        gcdPerson.theme = @"default";

//        [[NSNotificationCenter defaultCenter]postNotificationName:@"changelanguages" object:nil userInfo:nil];
        
        self.mainscreen.image = [UIImage imageNamed:@"styleswitchingmian"];//detailmid
        self.statebj.backgroundColor = [UIColor blackColor];
    }
    if(button.tag == 2){
        self.subjectselection.hidden = YES;
        self.subjectselectionone.hidden = NO;
    
        gcdPerson.theme = @"mianmidnight";
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"changelanguages" object:nil];
        self.mainscreen.image = [UIImage imageNamed:@"styleswitchingmid"];//detailmid
        self.statebj.backgroundColor = midnightRGB;
    }
    
    //    存入
      [[NSUserDefaults standardUserDefaults] setObject:gcdPerson.theme forKey:@"theme"];
      
      //这里建议同步存储到磁盘中，但是不是必须的
      [[NSUserDefaults standardUserDefaults] synchronize];
      
      //    读取
//      NSString *arr= [[NSUserDefaults standardUserDefaults] objectForKey:@"theme"];

    [[NSNotificationCenter defaultCenter]postNotificationName:@"changelanguages" object:nil userInfo:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
